import {reqGetMapdataByPage, reqGetMapdataCount, reqGetMapDataTop} from "@/api/mapdata";
import {requestGetData, requestIsSuccess} from "@/api/request";
import {getMapDateByType} from "@/utils/map";
import {warningMessage} from "@/utils/message";
import {MyMapOpt} from "@/class/map/myMapOpt";

export default{
    namespaced: true,
    state:{
        elementInDatabase: [],
        topElementInDatabase: [],
    },
    mutations:{
        PUSH_ELEMENT_TO_PAGE(state, item){
          state.elementInDatabase.push(item);
        },
        PUSH_ELEMENT_TO_TOP(state, item){
            state.topElementInDatabase.push(item);
        },
        CLEAR_ELEMENT_IN_PAGE(state,element){
            const index = state.elementInDatabase.findIndex(item=>item.mapData.id===element.mapData.id)
            state.elementInDatabase.splice(index,1);
        },
        CLEAR_ALL_ELEMENT_IN_PAGE(state){
            state.elementInDatabase.splice(0,state.elementInDatabase.length)
        },
        CLEAR_ALL_ELEMENT_IN_TOP(state){
            state.topElementInDatabase.splice(0,state.topElementInDatabase.length)
        }
    },
    actions:{
        addDataToPage({commit},features){
            features.forEach(feature=>{
                commit("PUSH_ELEMENT_TO_PAGE",feature);
            })
        },
        addDataToTop({commit},features){
            features.forEach(feature=>{
                commit("PUSH_ELEMENT_TO_TOP",feature);
            })
        },
    },
    getters:{}
}